package com.design.flyweight;

import java.util.Hashtable;

/**
 * @author leali
 * @title: IgoChessmanFactory
 * @projectName design
 * @description: 围棋棋子工厂类：享元工厂类，使用单例模式进行设计
 * @date 2022/1/3 1:04
 */
public class IgoChessmanFactory {
    /**
     * 使用Hashtable来存储享元对象，充当享元池
     */
    private static Hashtable<String, IgoChessman> chessmanHashtable;

    private IgoChessmanFactory() {
        chessmanHashtable = new Hashtable<>();
        IgoChessman black, white;
        black = new BlackIgoChessman();
        chessmanHashtable.put("b", black);
        white = new WhiteIgoChessman();
        chessmanHashtable.put("w", white);
    }
    /**
     * 通过key来获取存储在Hashtable中的享元对象
     *
     * @param color 旗子颜色
     * @return 旗子颜色
     */
    public static IgoChessman getIgoChessman(String color) {
        return chessmanHashtable.get(color);
    }
}
